
const { ccclass, property } = cc._decorator;

@ccclass
export class RankItem extends cc.Component {

    private grade: number = 0;
    private comboType: number = 0;
    private score: number = 0;

    protected onLoad(): void {

    }

    public initItem(type: number, grade: number, score: number) {
        this.comboType = type;
        this.grade = grade;
        this.score = score;
    }

    start() {
        this.initContent();
    }

    public updateContent(type: number, score: number) {
        this.comboType = type;
        this.score = score;
        this.initContent();
    }

    private initContent() {
        if (this.grade <= 3) {
            this.node.getChildByName("img_rank1").active = this.grade === 1;
            this.node.getChildByName("img_rank2").active = this.grade === 2;
            this.node.getChildByName("img_rank3").active = this.grade === 3;
            this.node.getChildByName("rankLabel").active = false;
        } else {
            this.node.getChildByName("rankLabel").getComponent(cc.Label).string = "" + this.grade;
            this.node.getChildByName("rankLabel").active = true;
        }
        for (let i = 1; i <= 4; i++) {
            let default_head = this.node.getChildByName("img_default_p" + i);
            let p_head = this.node.getChildByName("p" + i);
            let p_name = this.node.getChildByName(`p${i}_name`);
            let isShow = i <= this.comboType;
            default_head.active = isShow;
            p_head.active = isShow;
            p_name.active = isShow;
        }

        this.node.getChildByName("scoreLabel").getComponent(cc.Label).string = "" + this.score;
    }

    update(deltaTime: number) {

    }
}


